home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / pc / technical documentation / develop / additional articles / timing on the macintosh / timing code / src / microsecondtraptest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  1.9 KB  |  91 lines

  1. /*                                MicrosecondTrapTest.c                                */
  2. /*
  3.  * MicrosecondTrapTest.c
  4.  * Copyright © 1994 Apple Computer Inc.
  5.  * This is a test of the Microsecond trap available on recent systems.
  6.  * All it does is time a single mouse-click.
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "MicrosecondTrap.h"
  12. #include "MicrosecondTrapTest.h"
  13.  
  14.  
  15. #ifndef FALSE
  16. #define FALSE            0
  17. #define TRUE            1
  18. #endif
  19.  
  20. EventRecord                gEventRecord;
  21.  
  22. void                        ErrorExit(
  23.         OSErr                    errorStatus,
  24.         ConstStr255Param        errorMsg
  25.     );
  26.  
  27. void
  28. main(
  29. #ifdef THINK_C
  30.         int                        argc,
  31.         char                    **argv
  32. #endif
  33.     )
  34. {
  35.         UnsignedWide            start;
  36.         UnsignedWide            end;
  37.         UnsignedWide            elapsed;
  38.         double                    elapsedDouble;
  39.         Str255                    work;
  40.         short                    i;
  41.         DialogPtr                helloDialog;
  42.         
  43.         MaxApplZone();        
  44.         InitGraf(&qd.thePort);
  45.         InitFonts();
  46.         InitWindows();
  47.         InitMenus();
  48.         TEInit();
  49.         InitDialogs(0);
  50.         for (i = 0; i < 3; i++)
  51.             EventAvail(everyEvent, &gEventRecord);
  52.         /* */
  53.         if (MicrosecondTrapPresent() == FALSE)
  54.             ErrorExit(unimpErr, "\pMicrosecond Trap is not supported");
  55.         helloDialog = GetNewDialog(DLOG_Hello, NULL, (WindowPtr) -1);
  56.         if (helloDialog == NULL)
  57.             ErrorExit(resNotFound, "\pMissing dialog resource");
  58.         DrawDialog(helloDialog);
  59.         InitCursor();
  60.         while (Button() == FALSE)
  61.             ;
  62.         Microseconds(&start);
  63.         while (Button())
  64.             ;
  65.         Microseconds(&end);
  66.         DisposeDialog(helloDialog);
  67.         MicrosecondDelta(&start, &end, &elapsed);
  68.         elapsedDouble = MicrosecondToDouble(&elapsed) / 1000000.0;
  69.         sprintf((char *) &work[1], "%0.6lf", elapsedDouble);
  70.         work[0] = strlen((char *) &work[1]);
  71.         ParamText(work, "\p", "\p", "\p");
  72.         NoteAlert(DLOG_Goodbye, NULL);
  73.         ExitToShell();
  74. }
  75.  
  76. void
  77. ErrorExit(
  78.         OSErr                    errorStatus,
  79.         ConstStr255Param        errorMsg
  80.     )
  81. {
  82.         Str255                    work;
  83.         
  84.         NumToString(errorStatus, work);
  85.         ParamText(work, errorMsg, "\p", "\p");
  86.         InitCursor();
  87.         StopAlert(ALRT_Error, NULL);
  88.         ExitToShell();
  89. }
  90.  
  91.